<template>
  <common-layout>
    授权中...
  </common-layout>
</template>

<script>
import {authorization} from "@/services/workspace";
import CommonLayout from "@/layouts/CommonLayout.vue";


export default {
  name: 'Authorize',
  components: {CommonLayout},
  created() {
    const params = this.getQueryParams()
    authorization({
      random: params['random'],
      encryptionOptions: params['options']
    }).then(res => {
      console.log(res)
      if (res.message) {
        this.$message.error(res.message)
      } else {
        this.afterLogin(res);
      }
    })
  },
  methods: {
    afterLogin(res) {
      const loginRes = res.data
      if (loginRes.code === 200) {
        this.$message.success('登陆成功', 3)
        // 获取路由配置
        const params = this.getQueryParams()
        console.log("params=",params)
        this.$router.push('/'+params.menu)
      } else {
        this.error = loginRes.message
      }
    },
    getQueryParams() {
      const params = {}
      // 获取查询字符串（去掉开头的 ?）
      const queryString = window.location.href.split('?')[1]
      const pairs = queryString.split('&')
      for (const pair of pairs) {
        const [key, value] = pair.split('=')
        // 解码 URL 编码的字符（如 %20 → 空格）
        const decodedKey = decodeURIComponent(key)
        const decodedValue = decodeURIComponent(value || '')
        params[decodedKey] = decodedValue
      }
      return params
    }
  }
}
</script>

<style lang="less" scoped>
.search-form {
  margin-bottom: 24px;
}

.clearfix() {
  zoom: 1;
  &:before,
  &:after {
    content: ' ';
    display: table;
  }
  &:after {
    clear: both;
    visibility: hidden;
    font-size: 0;
    height: 0;
  }
}

.content {
  .clearfix();
  margin-top: 16px;
  margin-left: 40px;

  & > div {
    position: relative;
    text-align: left;
    float: left;
    width: 50%;

    p {
      line-height: 32px;
      font-size: 24px;
      margin: 0;
    }

    p:first-child {
      color: @text-color-second;
      font-size: 12px;
      line-height: 20px;
      margin-bottom: 4px;
    }
  }
}

</style>
<style lang="less">
// 滚动条位置
.__bar-is-vertical {
  right: -1px !important;
}

// 隐藏横向滚动条
.__bar-is-horizontal {
  display: none !important;
}
</style>
